cmake_minimum_required(VERSION 3.10)

if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
    if (DEFINED ENV{GBDKDIR})
        set(CMAKE_TOOLCHAIN_FILE "./cmake/gb.toolchain.cmake" CACHE PATH "toolchain file")
    else ()
        message(FATAL_ERROR "Please define GBDKDIR to point to your SDK path!")
    endif ()
endif ()

project(gb C)

set(GBDK $ENV{GBDKDIR})

if (NOT GBDK)
    message(FATAL_ERROR "GBDK environment variable is not set")
endif ()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories("${GBDK}/include" "include")

file(GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/src/*.c")

add_executable(${PROJECT_NAME} ${SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME} SUFFIX ".gb")
